<script type="text/javascript" src="__PUBLIC__/admin/js/kindeditor/kindeditor.js"></script>
<script type="text/javascript" src="__PUBLIC__/admin/js/kindeditor/lang/zh_CN.js"></script>
<script type="text/javascript">
function submitForm(action) {
    $(".submit").click(function(){
        if ("" == $.trim($("#title").val())) {
            popup.error("文章标题不能为空");
            return false;
        }
        if (0 == $.trim($("#typeid").val())) {
            popup.error("请选择文章栏目");
            return false;
        }

        var url = ('create' == action) ? "{:U('Content/create')}" : "{:U('Content/update')}";


        commonAjaxSubmit(url);
        return false;
    });
}

function ShowUrlTr()
{
	var jumpTest = $('#flagsj');
	var jtr = $('#redirecturltr');
	var jf = $('#redirecturl');
	if(jumpTest.prop("checked")){ 
		jtr.show();
	}else{
		jf.val("");
		jtr.hide();
	}
}
var up_token = "{$up_token}";
var up_salt = "{$up_salt}";
$(function(){
	$('#imgurls').uploadify({
		'formData'     : {
				'token' : up_token, 
				'salt' : up_salt,
				'sid' : "{$Think.session.sid}"
		},
		'swf'      : '__PUBLIC__/admin/js/uploadify/uploadify.swf',
		'uploader' : '{:U("Upload/image")}',
		'auto':true,
		'buttonText':"上传图片",//上传按钮的文字
		'cancelImage': '__PUBLIC__/admin/js/uploadify/uploadify-cancel.png',
		'multi':true,
		'queueID' : 'divFileProgressContainer',
		'removeTimeout' : 0,
		'overrideEvents': ['onSelectError', 'onDialogClose'],
		'fileTypeExts' : '*.jpg;*.gif;*.png',
		'fileSizeLimit' : "2MB",
		onDialogClose : function(queueData) { /*当文件选择对话框关闭时触发*/
		},
		onDialogOpen : function() { /*当选择文件对话框打开时触发*/
		},
		onSelect : function(file) { /*当每个文件添加至队列后触发*/
		},
		onSelectError : function(file,errorCode,errorMsg) { /*当文件选定发生错误时触发*/
			var e = this.settings;
			var eMsg = '';
			switch (errorCode) {
				case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
						eMsg += errorMsg;
					break;
				case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
					eMsg += '\n上传文件超出限制大小 (' + e.fileSizeLimit + ").";
					break;
				case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
					this.queueData.errorMsg += errorMsg;
					break;
				case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
					this.queueData.errorMsg += errorMsg;
					break;
			}
			alert(eMsg);
		},
		onUploadError : function(file, errorCode, errorMsg, errorString) { //上传文件出错是触发（每个出错文件触发一次）
			console.log(errorCode);
			console.log(errorMsg);
			console.log(errorString);
		},
		onUploadSuccess:function(file,data,response){
			//console.log(data);return false;
			var DataObj = $.parseJSON(data);
			if(response && DataObj.status){
				var img = DataObj.info;
				var _item = "<div class='albCt'><a class='delete_file' data-file='{FILEURL}' title='删除'>X</a><img class='img-thumbnail' style='height:100px;' src='{FILEURL}' /><input type='hidden' value='{FILEURL}' name='addtable[imgurls][]' /><input type='text' class='input' value='' name='addtable[imgtext][]' /></div>";
				var html = _item.replace(/\{FILEURL\}/g, img.fileurl);
				$("#thumbnails").append(html);
			}else{
				alert(DataObj.info);
			}
		}
	});
	$("#thumbnails").delegate(".delete_file", "click", function(){
		var _this = $(this), filepath = _this.data("file");
		popup.confirm('你确定要删除该文件吗？不可恢复！！','你确定要删除该文件吗',function(action){
			if(action == 'ok'){
				$.ajax({
					url : '{:U("Delfile/index")}',
					dataType : 'JSON',
					type : 'POST',
					data : {"filepath" : filepath, 'token' : up_token, 'salt' : up_salt},
					success : function(data){
						if(data.status){
							_this.parent(".albCt").remove();
						}else{
							popup.error(data.info);
						}
					}
				});
			}
		});
	});
	$("#thumbnails").delegate(".edit_delete_file", "click", function(){
		var _this = $(this), filepath = _this.data("file");
		popup.confirm('你确定要删除该文件吗？不可恢复！！','你确定要删除该文件吗',function(action){
			if(action == 'ok'){
				_this.parent(".albCt").hide();
				_this.siblings("input").attr("name", "delimgurls[]");
			}
		});
	});
})
</script>
